package com.siwei.mes.enums;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;

import java.util.Arrays;

/**
 * 品控类型  1-水泥 2-粉煤灰 3-矿渣粉 4-粗骨料 5-细骨料 6-外加剂 7-混凝土
 * ERP类型是中文 只有 粗骨料，细骨料，水泥，矿粉，水，掺合料，外加剂，其他
 * 对应协会code
 * 1-水泥   1101
 * 2-粉煤灰 1117
 * 3-矿渣粉 1124
 * 4-粗骨料 1102
 * 5-细骨料 1103,1203
 * 6-外加剂 1116
 * 7-混凝土 1112,1108,1110,1109
 *
 * @Description: 物料类型枚举   字典表（MASTERIAL_TYPE）
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2023/12/23 22:16
 */
@Getter
public enum MaterialsEnum {
    CEMENT(1, "水泥", "CEMENT", "水泥", "1101"),
    FLY(2, "粉煤灰", "FLY_ASK", "掺合料", "1117"),
    SLAG(3, "矿渣粉", "SLAG", "矿粉", "1124"),
    COARSE(4, "粗骨料", "COARSE_AGGREGATE", "粗骨料", "1102"),
    FINE(5, "细骨料", "FINE_AGGREGATE", "细骨料", "1103,1203"),
    ADMIXTURE(6, "外加剂", "CONCRETE_ADMIXTURE", "外加剂", "1116"),
    CONCRETE(7, "混凝土", "CONCRETE", "混凝土", "1112,1108,1110,1109"),
    WATER(8, "水", "WATER", "水", null);

    @ApiModelProperty(value = "类型id")
    private Integer code;

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "对应试验项目描述")
    private String testProjectType;

    @ApiModelProperty(value = "erp对应的物料名称")
    private String erpType;

    @ApiModelProperty(value = "对应协会code")
    private String laboratoryItemId;

    MaterialsEnum(Integer code, String name, String testProjectType, String erpType, String laboratoryItemId) {
        this.code = code;
        this.name = name;
        this.testProjectType = testProjectType;
        this.erpType = erpType;
        this.laboratoryItemId = laboratoryItemId;
    }

    /**
     * 根据code查找信息
     *
     * @param code 物料类型
     * @return
     */
    public static MaterialsEnum selectByCode(Integer code) {
        return Arrays.stream(values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
    }


    /**
     * 根据erpType查找信息
     *
     * @param erpType erp类型
     * @return
     */
    public static MaterialsEnum selectByErpType(String erpType) {
        return Arrays.stream(values()).filter(e -> e.getErpType().equals(erpType)).findFirst().orElse(null);
    }

    /**
     * 根据试验项目类型查找
     *
     * @param testProjectType
     * @return
     */
    public static MaterialsEnum selectByTypeProjectType(String testProjectType) {
        return Arrays.stream(values()).filter(e -> e.getTestProjectType().equals(testProjectType)).findFirst().orElse(null);
    }
}
